package leetcode.editor.day;

// 1470. 重新排列数组
// https://leetcode.cn/problems/shuffle-the-array/description/
class ShuffleTheArray {
    public static void main(String[] args) {
        Solution solution = new ShuffleTheArray().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        // 一次遍历
        public int[] shuffle(int[] nums, int n) {
            int[] ans = new int[nums.length];
            int l = 0, r = nums.length / 2;
            for (int i = 0; i < nums.length; i++) {
                if (i % 2 == 0) ans[i] = nums[l++];
                else ans[i] = nums[r++];
            }

            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
